from django.views.generic import date_based, list_detail
from nx.blog.models import Post

months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
meses  = ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 'ago', 'set', 'out', 'nov', 'dez']

def to_english(month):
    try:
        return months[meses.index(month.lower())]
    except ValueError:
        return month

def post_list(request, page=0, **kwargs):
    return list_detail.object_list(
        request,
        queryset = Post.objects.published(),
        paginate_by = 20,
        page = page,
        **kwargs
    )
post_list.__doc__ = list_detail.object_list.__doc__

def post_detail(request, slug, year, month, day, **kwargs):
    return date_based.object_detail(
        request,
        year = year,
        month = month,
        day = day,
        date_field = 'published',
        slug = slug,
        queryset = Post.objects.published(),
        **kwargs
    )
post_detail.__doc__ = date_based.object_detail.__doc__